<html>
<head><meta charset="utf-8"><title>Tuplestruct type alias destructuring · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tuplestruct.20type.20alias.20destructuring.html">Tuplestruct type alias destructuring</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230020956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tuplestruct%20type%20alias%20destructuring/near/230020956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tuplestruct.20type.20alias.20destructuring.html#230020956">(Mar 12 2021 at 12:30)</a>:</h4>
<p>I looked around a bit but couldn't find a reason as to why, so maybe someone here know. Why can you destructure through a Record-TypeAlias but not through a Tuple-TypeAlias? </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Record</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kt">i32</span>: <span class="kt">i32</span>
<span class="p">}</span><span class="w"></span>

<span class="k">type</span> <span class="nc">RecordAlias</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Record</span><span class="p">;</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Tuple</span><span class="p">(</span><span class="kt">i32</span><span class="p">);</span><span class="w"></span>
<span class="k">type</span> <span class="nc">TupleAlias</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Tuple</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">Record</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="p">}</span>: <span class="nc">Record</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">RecordAlias</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="p">}</span>: <span class="nc">RecordAlias</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">Tuple</span><span class="p">(</span><span class="kt">i32</span><span class="p">)</span>: <span class="nc">Tuple</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">TupleAlias</span><span class="p">(</span><span class="kt">i32</span><span class="p">)</span>: <span class="nc">TupleAlias</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f9dd23d02c21d1521db017c6aa4acddc">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f9dd23d02c21d1521db017c6aa4acddc</a><br>
Gives (only) the following error</p>
<div class="codehilite"><pre><span></span><code>error[E0532]: expected tuple struct or tuple variant, found type alias `TupleAlias`
  --&gt; src/main.rs:14:9
   |
14 |     let TupleAlias(i32): TupleAlias;
   |         ^^^^^^^^^^
   |
   = note: can&#39;t use a type alias as a constructor
</code></pre></div>
<p>which honestly is a bit confusing anyways, as the struct constructor isn't being used here?</p>



<a name="230021332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tuplestruct%20type%20alias%20destructuring/near/230021332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tuplestruct.20type.20alias.20destructuring.html#230021332">(Mar 12 2021 at 12:34)</a>:</h4>
<p>I think the constructor also "constructs" patterns, in a way, and the type alias doesn't alias the constructor since it's in the value namespace</p>



<a name="230022675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tuplestruct%20type%20alias%20destructuring/near/230022675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tuplestruct.20type.20alias.20destructuring.html#230022675">(Mar 12 2021 at 12:45)</a>:</h4>
<p>Ah, that would make sense, kind of a shame it doesn't work <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>



<a name="230050894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tuplestruct%20type%20alias%20destructuring/near/230050894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tuplestruct.20type.20alias.20destructuring.html#230050894">(Mar 12 2021 at 15:48)</a>:</h4>
<p>There is some discussion of this at <a href="https://github.com/rust-lang/rust/issues/73191">#73191</a>. (I think that is the same thing.)</p>



<a name="230065018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tuplestruct%20type%20alias%20destructuring/near/230065018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tuplestruct.20type.20alias.20destructuring.html#230065018">(Mar 12 2021 at 17:08)</a>:</h4>
<p>That looks like its related ye</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>